#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char **argv)
{
	Mat img, imgHSV, mask;
	VideoCapture cap = VideoCapture("/dev/video0");

	int hmin = 0, smin = 0, vmin = 0;
	int hmax = 179, smax = 255, vmax = 255;
	// 创建跟踪栏窗口
	namedWindow("Trackbars", (640, 200));
	// 创建跟踪栏
	createTrackbar("Hue Min", "Trackbars", &hmin, 179);
	createTrackbar("Hue Max", "Trackbars", &hmax, 179);
	createTrackbar("Sat Min", "Trackbars", &smin, 255);
	createTrackbar("Sat Max", "Trackbars", &smax, 255);
	createTrackbar("Val Min", "Trackbars", &vmin, 255);
	createTrackbar("Val Max", "Trackbars", &vmax, 255);

	while (1)
	{
		cap.read(img);

		cvtColor(img, imgHSV, COLOR_BGR2HSV);
		// 收集颜色
		// 定义颜色上下限
		Scalar lower(hmin, smin, vmin);
		Scalar upper(hmax, smax, vmax);
		// 输出的是遮罩，蒙版
		inRange(imgHSV, lower, upper, mask);
		// 展示

		imshow("Image", img);
		cv::rotate(img, img, cv::ROTATE_90_CLOCKWISE);
		imshow("ImageHSV", img);
		imshow("ImageMask", mask);
		waitKey(1);
	}
}